package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.framework.web.page.TableDataInfoMy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyGoods;
import com.laowang.project.system.service.MyGoodsService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 商品Controller
 *
 * @author laowang
 * @date 2023-07-19
 */
@Api(tags = "商品接口")
@RestController
@RequestMapping("/myGoods")
public class MyGoodsController extends BaseController {
    @Autowired
    private MyGoodsService myGoodsService;





    /**
     * 查询商品列表
     */
    @ApiOperation(value = "小程序端 查询商品列表",notes = "")
    @GetMapping("/web/list")
    public TableDataInfoMy weblist(MyGoods myGoods) {
        startPage();
        myGoods.setMarketable(1);
        List<MyGoods> list = myGoodsService.selectMyGoodsListWeb(myGoods);
        return getDataTableMy(list);
    }

    /**
     * 查询商品列表
     */
    @ApiOperation(value = "小程序端 查询商品详情",notes = "")
    @GetMapping("/web/{id}")
    public AjaxResult weblist(@PathVariable("id") Integer id) {
        MyGoods myGoods = myGoodsService.selectMyGoodsById(id);
        return AjaxResult.success("操作成功",myGoods);
    }

    /**
     * 查询商品列表
     */
    @ApiOperation(value = "查询商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyGoods myGoods) {
        startPage();
        List<MyGoods> list = myGoodsService.selectMyGoodsList(myGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @ApiOperation(value = "导出商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:export')")
    @GetMapping("/export")
    public AjaxResult export(MyGoods myGoods) {
        List<MyGoods> list = myGoodsService.selectMyGoodsList(myGoods);
        ExcelUtil<MyGoods> util = new ExcelUtil<MyGoods>(MyGoods.class);
        return util.exportExcel(list, "myGoods");
    }

    /**
     * 获取商品详细信息
     */
    @ApiOperation(value = "获取商品详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myGoodsService.selectMyGoodsById(id));
    }

    /**
     * 新增商品
     */
    @ApiOperation(value = "新增商品",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyGoods myGoods) {
        return toAjax(myGoodsService.insertMyGoods(myGoods));
    }

    /**
     * 修改商品
     */
    @ApiOperation(value = "修改商品",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyGoods myGoods) {
        return toAjax(myGoodsService.updateMyGoods(myGoods));
    }

    /**
     * 删除商品
     */
    @ApiOperation(value = "删除商品",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myGoods:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myGoodsService.deleteMyGoodsByIds(ids));
    }
}
